<template>
  <div id="app">
    <!-- <router-view /> -->
    <router-view v-if="isRouterAlive" />
  </div>
</template>

<script>
// import { removeToken } from '@/utils/auth'

export default {
  name: 'App',
  provide() {
    return {
      reload: this.reload
    }
  },
  data() {
    return {
      isRouterAlive: true
    }
  },
  created() {
    // 初始化
    this.$store.dispatch('setting/init')
  },
  updated() {
    // 绑定界面刷新事件
    window.addEventListener('unload', this.saveState)
    document.body.ondragstart = null
  },
  methods: {
    // 当页面刷新时vuex存储的数据会消失，因此一般使用sessionStorage处理
    saveState() {
      // 缓存 State
      sessionStorage.setItem('state', JSON.stringify(this.$store.state))
    },
    reload() {
      this.isRouterAlive = false
      this.$nextTick(function() {
        this.isRouterAlive = true
      })
    }
  }
}
</script>
<style lang="scss" scoped>
@import "@/styles/flex.scss";
</style>
